#include<iostream>
using namespace std;
const int N = 1010;
int r = 0;
int a[N][N];
int f[N][N];
int ret;
int main()
{
	cin >> r;
	for (int i = 1;i <= r;i++)
	{
		for (int j = 1;j <= i;j++)
		{
			cin >> a[i][j];
		}
	}
	//根据正上方和左上方的两个点计算这个位置
	//路径最大取max
	//从左往右依次填入
	for (int i = 1;i <= r;i++)
	{
		for (int j = 1;j <= i;j++)
		{
			f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]) + a[i][j];
		}
	}
	//查找最底下一行的最大值
	for (int i = 1;i <= r;i++)
	{
		ret = max(ret, f[r][i]);
	}
	cout << ret << endl;
	return 0;
}